<%-- 
    Document   : queue
    Created on : May 5, 2013, 11:40:58 PM
    Author     : Lord Makuta
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="db.UserDAO"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="db.DB"%>
<%
    if (session.getAttribute("user")==null)
    {
        response.sendRedirect("register.jsp");
        return;
    }
    try
    {
        String id=request.getParameter("id");

        DB data=new DB();
        Connection conn=data.getConnection();
        Statement stm=conn.createStatement();

        String ins="INSERT INTO MovieQ (AccountId, MovieId) VALUES ("+((UserDAO)session.getAttribute("user")).getId() +", "+id+")";
        stm.executeUpdate(ins);

        ResultSet res=stm.executeQuery("SELECT NumCopies FROM Movie WHERE Id="+id);
        res.next();
        int copies=res.getInt(1);
        copies--;
        stm.executeUpdate("UPDATE Movie SET NumCopies="+copies+" WHERE Id="+id);
    }
    catch(Exception e)
    {
        
    }
    response.sendRedirect("MyAccount");
%>